#include "MonitoringTool.h"
#include <QFile>
#include <QStandardPaths>
#include <QDebug>
#include <QApplication>
#include <QRegularExpression>
MonitoringTool::MonitoringTool(QObject *parent) : QObject(parent)
{
    QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/config.ini";
    qDebug() << path;
    m_set=new QSettings(path,QSettings::IniFormat);
}

void MonitoringTool::setStlyeSheet(const QString &css)
{
    QFile file(css);
    if(!file.open(QFile::ReadOnly)){
        qDebug()<<"打开失败";
        return;
    }
    static_cast<QApplication *>(QCoreApplication::instance())->setStyleSheet(file.readAll());
    file.close();
}

QString MonitoringTool::readData(const QString&path)  {
  //  userName=m_set->value("options2/username").toString();
   // password=m_set->value("options2/password").toString();
    return m_set->value(path).toString();
}

void MonitoringTool::writeData(const QString&path,const QString&value)
{
//    m_set->setValue("options2/username","lisi");
//    m_set->setValue("options2/password","lisi123");
    m_set->setValue(path,value);
}

bool MonitoringTool::isPhoneNumberValid(const QString &phoneNumber)
{
    // 定义手机号的正则表达式
        QRegularExpression regex("^1[3-9]\\d{9}$");
        // 执行匹配操作
        QRegularExpressionMatch match = regex.match(phoneNumber);
        // 判断是否匹配成功
        return match.hasMatch();
}

QString MonitoringTool::getNowTimes()
{
    // 获取当前日期和时间
        QDateTime currentDateTime = QDateTime::currentDateTime();

        // 将日期时间格式化为字符串
        QString dateTimeString = currentDateTime.toString("yyyy-MM-dd hh:mm:ss");
        return dateTimeString;

}


